﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommonUtils
{
    public static class LogRun
    {
        static Log log = new Log("Run", new Log4netWrapper("Running"));
        static Log log_Operator = new Log("Run", new Log4netWrapper("Operator"));
        static Log log_Business = new Log("Biz", new Log4netWrapper("Business"));
        /// <summary>
        /// 信息
        /// </summary>
        /// <param name="msg"></param>
        public static void Info(string msg)
        {
            if (string.IsNullOrEmpty(msg))
                return;
            log.I(msg);
        }

        /// <summary>
        /// 警告
        /// </summary>
        /// <param name="msg"></param>
        public static void Warning(string msg)
        {
            if (string.IsNullOrEmpty(msg))
                return;
            log.W(msg);
        }

        /// <summary>
        /// 异常
        /// </summary>
        /// <param name="msg"></param>
        public static void Error(string msg)
        {
            if (string.IsNullOrEmpty(msg))
            {
                msg = "未知异常！";
            }
            var stackTrace = new System.Diagnostics.StackTrace();
            string methodBase = stackTrace.GetFrame(1).GetMethod().Name;
            msg = $"{methodBase}|{msg}";
            log.E(msg);
        }

        /// <summary>
        /// 致命错误
        /// </summary>
        /// <param name="msg"></param>
        public static void Fatal(string msg)
        {
            if (string.IsNullOrEmpty(msg))
                return;
            log.F(msg);
        }

        /// <summary>
        /// 仅输出到输出窗口
        /// </summary>
        /// <param name="msg"></param>
        public static void Output(string msg, bool isConsolePut = true)
        {
            if (string.IsNullOrEmpty(msg))
                return;
            if (isConsolePut)
            {
                Console.WriteLine($"{DateTime.Now.ToString("yyyyMMdd HH:mm:ss fff")}|{msg}");
            }
            log.I(msg);
        }

        /// <summary>
        /// 用户操作日志
        /// </summary>
        /// <param name="msg"></param>
        public static void Operator(string msg)
        {
            if (string.IsNullOrEmpty(msg))
                return;
            log_Operator.I(msg);
        }

        /// <summary>
        /// 用户操作日志
        /// </summary>
        /// <param name="msg"></param>
        public static void BusinessError(string msg)
        {
            if (string.IsNullOrEmpty(msg))
                return;
            log_Business.E(msg);
        }
    }
}
